package routers

import (
	"5title_gin/global"
	"5title_gin/internal/api/middleware"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	gs "github.com/swaggo/gin-swagger"
	"go.uber.org/zap"
)

func Run() {
	gin.SetMode(global.Config.System.Mode)
	r := gin.Default()

	r.Static("/uploads", "uploads")
	r.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))

	addr := global.Config.System.Addr()
	r.Use(middleware.Cors())
	r.Use(middleware.LimitMiddleware(5))
	a := r.Group("api")
	g := r.Group("api")
	g.Use(middleware.AuthMiddleware)
	UserRouter(g, a)
	SystemRouter(g)
	if global.Config.System.Mode == "release" {
		zap.S().Infof("✨ 服务器启动成功！(≧▽≦) 🎉，访问地址为：%s", addr)

	}

	r.Run(addr)
}
